function h_item = guimenu(h_menu, varargin);

% GUIMENU - create a menu with the provided parameters
%
%    H_ITEM = GUIMENU(H_MENU, 'Name1', value1, ...) creates menu
%    items whose parent UIMENU or UICONTEXTMENU object handle is
%    H_MENU.  The menu item properties are specified by pairs of
%    the form NAME/VALUE, where the property name is provided by
%    a string NAME and the property values for each menu item are
%    given by a subsequent cell array VALUE.  The menu item object
%    handles are returned as the vector H_ITEM.

% By:   S.C. Molitor (smolitor@bme.jhu.edu)
% Date: April 15, 1999

% check input parameters

if (nargin < 3)
   return
elseif (~istype(h_menu, 'uimenu') & ~istype(h_menu, 'uicontextmenu'))
   return
end

% make sure inputs are property name/value pairs
% create cell array to store name/value pairs
% count number of menu items

num_item = 0;
num_prop = 0;
for i = 1 : 2 : length(varargin)
   if (ischar(varargin{i}) & iscell(varargin{i + 1}))
      num_prop = num_prop + 1;
      prop_name{num_prop} = varargin{i};
      var_value = varargin{i + 1};
      if (num_item == 0)
         num_item = length(var_value);
      else
         num_item = min(num_item, length(var_value));
      end
      for j = 1 : num_item
         prop_value{j, num_prop} = var_value{j};
      end
   else
      return
   end
end

% setup menu items

h_item = zeros(1, num_item);
for i = 1 : num_item
   h_item(i) = uimenu(h_menu);
   for j = 1 : num_prop
      set(h_item(i), prop_name{j}, prop_value{i, j});
   end
end
return
